﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScheduleMaker.DB.Domain;
using ScheduleMaker.DB.Domain.Core;

namespace ScheduleMaker.DB.CoreDAO
{
    public class HourDAO : CoreAbstractDAO<Hour>
    {
        private AdapterAbstractDAO<Hour, HourSchool> wrappedAbstractDAOSchool;
        private AdapterAbstractDAO<Hour, HourUniversity> wrappedAbstractDAOUniversity;
        private HourDAOSchool wrappedDAOSchool;
        private HourDAOUniversity wrappedDAOUniversity;

        public HourDAO(HourDAOSchool wrappedDAOSchool)
        {
            this.wrappedDAOSchool = wrappedDAOSchool;
            this.wrappedAbstractDAOSchool =
                new AdapterAbstractDAO<Hour, HourSchool>((AbstractDAO<HourSchool>)wrappedDAOSchool);
        }

        public HourDAO(HourDAOUniversity wrappedDAOUniversity)
        {
            this.wrappedDAOUniversity = wrappedDAOUniversity;
            this.wrappedAbstractDAOUniversity =
                new AdapterAbstractDAO<Hour, HourUniversity>((AbstractDAO<HourUniversity>)wrappedDAOUniversity);
        }

        public override void update(Hour entity)
        {
            if (wrappedDAOSchool != null)
            {
                wrappedAbstractDAOSchool.update(entity);
            }
            else if (wrappedDAOUniversity != null)
            {
                wrappedAbstractDAOUniversity.update(entity);
            }
            else
            {
                throw new NotImplementedException("Neither wrapped HourDAOSchool nor HourDAOUniversity was initialized");
            }
        }

        public override void save(Hour entity)
        {
            if (wrappedDAOSchool != null)
            {
                wrappedAbstractDAOSchool.save(entity);
            }
            else if (wrappedDAOUniversity != null)
            {
                wrappedAbstractDAOUniversity.save(entity);
            }
            else
            {
                throw new NotImplementedException("Neither wrapped HourDAOSchool nor HourDAOUniversity was initialized");
            }
        }

        public override void saveOrUpdate(Hour entity)
        {
            if (wrappedDAOSchool != null)
            {
                wrappedAbstractDAOSchool.saveOrUpdate(entity);
            }
            else if (wrappedDAOUniversity != null)
            {
                wrappedAbstractDAOUniversity.saveOrUpdate(entity);
            }
            else
            {
                throw new NotImplementedException("Neither wrapped HourDAOSchool nor HourDAOUniversity was initialized");
            }
        }

        public override void delete(Hour entity)
        {
            if (wrappedDAOSchool != null)
            {
                wrappedAbstractDAOSchool.delete(entity);
            }
            else if (wrappedDAOUniversity != null)
            {
                wrappedAbstractDAOUniversity.delete(entity);
            }
            else
            {
                throw new NotImplementedException("Neither wrapped HourDAOSchool nor HourDAOUniversity was initialized");
            }
        }

        public override Hour getById(int id)
        {
            Hour entity;
            if (wrappedDAOSchool != null)
            {
                entity = wrappedAbstractDAOSchool.getById(id);
            }
            else if (wrappedDAOUniversity != null)
            {
                entity = wrappedAbstractDAOUniversity.getById(id);
            }
            else
            {
                throw new NotImplementedException("Neither wrapped HourDAOSchool nor HourDAOUniversity was initialized");
            }

            return entity;
        }

        public override IList<Hour> getAll()
        {
            IList<Hour> records;
            if (wrappedDAOSchool != null)
            {
                records = wrappedAbstractDAOSchool.getAll();
            }
            else if (wrappedDAOUniversity != null)
            {
                records = wrappedAbstractDAOUniversity.getAll();
            }
            else
            {
                throw new NotImplementedException("Neither wrapped HourDAOSchool nor HourDAOUniversity was initialized");
            }

            return records;
        }
    }
}
